<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="image/css.css" type="text/css" />
<title>管理</title>
<style >body{color:#000;background:#fff;padding:6px 0 0;margin:0;position:relative;font-size:12px;}
body,th,td,.p1,.p2{font-family:arial}p,form,ol,ul,li,dl,dt,dd,h3{margin:0;padding:0;list-style:none}
</style>
</head>
<body>
<?php
include 'Nav.php';
include 'configs\config.php';
$mysql = new mysql();
$mysql->open($config);

$show = @trim($_GET['show']);
$query = $mysql->select('*', 'sms_type');
$query[]=array('ID'=>'0','type_name'=>'精选内容');
//echo '<pre>';
//print_r($query);

$str = '';
@$typeid = $_GET['typeid'];
@$isfavoriteid = $_GET['isfavorite'];
foreach($query as $v)
{
	if($v['ID']==$typeid)
	{
		$check = 'selected="selected"';
	}
	else
	{
		$check = '';
	}
	$str.='<option value="'.$v['ID'].'" '. $check .'>'.$v['type_name'].'</option>'."\n";
}


@$id = $_GET['id'];
 

if(!empty($id))
{
	$where = "id=".$id;
}
else
{
//	echo 'id不存';exit();
}

$query = $mysql->select('*', 'sms_content',$where);

//print_r($query);

$isfavoriteArr = array('0'=>'一般内容','1'=>'收藏内容','2'=>'精选内容');
$str1 = '';
foreach($isfavoriteArr as $k => $v)
{
	if($k == $isfavoriteid)
	{
		$check = 'selected="selected"';
	}
	else
	{
		$check = '';
	}
	$str1.='<option value="'.$k.'" '. $check .'>'.$v.'</option>'."\n";
}

$strAddHtml = <<< STRHTML
<form action="?show=moddata&id=__ID__&typeid=__TYPEID__" method="post">
分类: <select name="typeid">
__select__</select><br/>
内容: <textarea name="smscontent" rows="4" cols="70">__content__</textarea><br/><br/>
标记: <select name="is">

__isfavorite__
</select><br/>
<input type="submit" name="sub" value="================提交,提交==============" /><br/>
</form>
STRHTML;

$strAddHtml = str_replace("__select__", $str, $strAddHtml);
$strAddHtml = str_replace("__content__", $query[0]['content'], $strAddHtml);
$strAddHtml = str_replace("__ID__", $query[0]['ID'], $strAddHtml);
$strAddHtml = str_replace("__TYPEID__", $query[0]['typeid'], $strAddHtml);
$strAddHtml = str_replace("__isfavorite__", $str1, $strAddHtml);
echo $strAddHtml;



$typeid    = @trim($_POST['typeid']);
$smscontent      = @trim($_POST['smscontent']);
$is = @trim($_POST['is']);

if($show == 'moddata'){
		$data =array();
		$data['content'] = $smscontent;
		$data['typeid'] = $typeid;
		$data['isfavorite']  = $is;
		$id = @trim($_GET['id']);
		$where = 'id='.$id;

//		foreach ($data as $value){
//			if($value==''){
//				header("location:smsmanage.php");
//				exit();
//			}
//		}
		var_dump($data);
		var_dump($where);

		$res = $mysql->update($data,'sms_content',$where);

		header("location:sms_manage.php?show=id&id=".$typeid);
}









unset($mysql);
?>
</body>
</html>